﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using System.Reflection;
using System.Threading;
using System.Resources;
using System.Web.Routing;
using ShipWorkDataModel.DataModel;
namespace ShipWork.Models
{
    public class CultureModels
    {
        public static void SetCultureInfo(string cultureinfo)
        {
            try
            {
                CultureInfo currentculture = new CultureInfo(cultureinfo);
                Thread.CurrentThread.CurrentUICulture = currentculture;
                Thread.CurrentThread.CurrentCulture = currentculture;
            }
            catch
            { }
        }
    }
    public class LanguageModels
    {
        public static IQueryable<T_Language> GetAllSupportLanguages()
        {
            ShipWorkDBEntities db = new ShipWorkDBEntities();
            return db.T_Language.AsQueryable();
        }
        public static string GetPhysicalPath(RequestContext rc)
        {
            string apppath = rc.HttpContext.Request.PhysicalApplicationPath;
            string controller = rc.RouteData.Values["controller"].ToString();
            return apppath + "Views\\" + controller+"\\";
        }
    }
    public class MenuModels
    {

        public static IQueryable<T_Menu> GetAllMenus()
        {
            ShipWorkDBEntities db = new ShipWorkDBEntities();
            return db.T_Menu.AsQueryable();
        }
        public static IQueryable<T_Menu> GetChildMenusByPId(string Parent_Id, string MenuIdLike = "")
        {
            if (string.IsNullOrEmpty(MenuIdLike))
            {
                ShipWorkDBEntities db = new ShipWorkDBEntities();
                return db.T_Menu.Where(d => d.Parent_Id == Parent_Id);
            }
            else
            {
                ShipWorkDBEntities db = new ShipWorkDBEntities();
                return db.T_Menu.Where(d => d.Parent_Id == Parent_Id && d.Menu_Id.StartsWith(MenuIdLike));
            }
        }
    }
    public class ResourceGet
    {
        public static string GetResValueByKey(string key)
        {
            return HttpContext.GetGlobalResourceObject("GameTown", key) == null ? " " : HttpContext.GetGlobalResourceObject("GameTown", key).ToString();
        }
        public static string GetResValueByKey(string key,string currentLangId)
        {
            CultureModels.SetCultureInfo(currentLangId);
            return HttpContext.GetGlobalResourceObject("GameTown", key) == null ? " " : HttpContext.GetGlobalResourceObject("GameTown", key).ToString();
        }
    }
    public class AboutModels
    {
        public string AboutPageName { get; set; }
        public string AboutText { get; set; }
        public bool success { get; set; }
    }

}